package vn.personal.anhht.bloback12.activity;

import vn.personal.anhht.bloback12.widget.ActionBar;
import vn.personal.anhht.bloback12.widget.ActionBar.Action;
import vn.personal.anhht.bloback12.widget.ActionBar.IntentAction;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class HomeActivity extends BloBack12Activity implements OnClickListener{
    
    private ImageButton blacklist;
    private ImageButton blocksms;
    private ImageButton blockcall;
    private ImageButton privacyeraser;
    private ImageButton privacyspace;
    private ImageButton backup;    
    private Resources rs;
    private String TAG = "HomeActivity";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);
        rs = getResources();
        logE(TAG, "This is HomeActivity");
        final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
        actionBar.setTitle(rs.getString(R.string.actionbar_title));

        final Action aboutAction = new IntentAction(this, createShareIntent(),
                R.drawable.ic_action_about);
        actionBar.addAction(aboutAction);
        final Action helpAction = new IntentAction(this, createShareIntent(),
                R.drawable.ic_action_help);
        actionBar.addAction(helpAction);
        final Action otherAction = new IntentAction(this, new Intent(this,
                SettingActivity.class), R.drawable.ic_action_settings);
        actionBar.addAction(otherAction);
        initButton();
    }
    
    private void initButton(){
        blacklist = (ImageButton)findViewById(R.id.ib_blacklist);
        blacklist.setOnClickListener(this);
        blocksms = (ImageButton)findViewById(R.id.ib_blocksms);
        blocksms.setOnClickListener(this);
        blockcall = (ImageButton)findViewById(R.id.ib_blockcall);
        blockcall.setOnClickListener(this);
        backup = (ImageButton)findViewById(R.id.ib_backup);
        backup.setOnClickListener(this);
        privacyeraser = (ImageButton)findViewById(R.id.ib_privacyeraser);
        privacyeraser.setOnClickListener(this);
        privacyspace = (ImageButton)findViewById(R.id.ib_privacyspace);
        privacyspace.setOnClickListener(this);
    }
    

    public static Intent createIntent(Context context) {
        Intent i = new Intent(context, HomeActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return i;
    }

    private Intent createShareIntent() {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "Shared from the ActionBar widget.");
        return Intent.createChooser(intent, "Share");
    }

    @Override
    public void onClick(View v) {
        if(v == blacklist){
            startMyActivity(BlacklistActivity.class);
        }else if (v == blockcall) {
            startMyActivity(LogCallActivity.class);
        }else if (v == blocksms) {
            startMyActivity(LogSMSActivity.class);
        }else if (v == backup) {
            showToastShort("This is a backup");
        }else if (v == privacyeraser) {
            startMyActivity(LogActivity.class);
        }else {
            showToastShort("This is a privacy space");
        }
    }
}